package com.caigou.modules.home.widget

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.Window
import android.widget.ImageView
import android.widget.TextView
import com.caigou.comm.base.bean.PrizeItemBean
import com.caigou.comm.base.ext.prizeBallColor
import com.caigou.comm.base.widget.ScratchCardView
import com.caigou.modules.home.R

/**
 * @author #Suyghur.
 * Created on 2022/02/23
 */
class ScratchCardDialog(context: Context, private val ball: PrizeItemBean, private val callback: () -> Unit) : Dialog(context) {

    private lateinit var scratchCardView: ScratchCardView
    private lateinit var tvNum: TextView
    private lateinit var tvDesc: TextView
    private lateinit var ivClose: ImageView

    init {
        setCanceledOnTouchOutside(true)
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        initView()
    }

    private fun initView() {
        setContentView(R.layout.dialog_scratch_card)
        tvNum = findViewById(R.id.scratch_card_tv_prize_num)
        tvNum.text = ball.number
        tvNum.setBackgroundResource(prizeBallColor(ball.numberColor))

        tvDesc = findViewById(R.id.scratch_card_tv_prize_desc)
        tvDesc.text = ball.animalName

        scratchCardView = findViewById(R.id.scratch_card_scv)
        scratchCardView.setOnScratchFinishedListener {
            callback()
        }

        ivClose = findViewById(R.id.scratch_card_iv_close)
        ivClose.setOnClickListener {
            dismiss()
        }
    }
}